<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="net.sf.json.JSONObject"%>
<%@page import="com.sinodata.bsm.center.util.spring.SpringContextHolder"%>
<%@page import="com.sinodata.bsm.center.service.config.PortalService"%>
<%@page import="com.sinodata.bsm.common.constants.EventConstants"%>
<%@page import="com.sinodata.bsm.center.web.action.portlet.TopParamConstants"%>
<%@page import="com.sinodata.bsm.center.user.UserUtil"%>
<%@page import="com.sinodata.bsm.center.purview.UserFunctionValidate"%>
<%@page import="com.sinodata.bsm.center.purview.FunctionConstants"%>
<%
String param = request.getParameter("args");
JSONObject parameter = "".equals(param) ? null : JSONObject.fromObject(param);
Integer level = null;
Integer limitsNum = null;
Integer status = null;
if(parameter == null){
    level = -1;
    status = -1;
    limitsNum = TopParamConstants.TOPN_DATA_PAGENUMBER;
}else{
    level = Integer.valueOf(parameter.getString("PARAM_level"));
    status = Integer.valueOf(parameter.getString("PARAM_status"));
    limitsNum = Integer.valueOf(parameter.getString("PARAM_limitsNum"));
}

StringBuffer sql = new StringBuffer();
sql.append("select to_char(e.occur_time,'yyyy-MM-dd hh24:mi:ss') as occurTime,");
sql.append(" e.status as status,");
sql.append(" e.level_ as lv,");
sql.append(" e.id as id,");
sql.append(" e.msg as msg");
sql.append(" from (select t.*,rownum from event t order by t.occur_time desc) e");
sql.append(" left outer join res r on e.res_id=r.id");
sql.append(" where rownum <="+limitsNum);
sql.append(" and e.CATALOG = 1 and e.filter_event_id is null and e.status != 2");
List<Long> authScopeList = UserFunctionValidate.getResIdListForUser(FunctionConstants.VIEW_RES);
if(!UserUtil.getInstance().isSysAdmin(UserUtil.getInstance().getCurrentUserId()) && authScopeList != null && authScopeList.size()!=0){
    sql.append("and (r.id").append(" in (");
    StringBuffer str = new StringBuffer();
    for (Long resId : authScopeList) {
        str.append(resId).append(",");
    }
    str.delete(str.lastIndexOf(","), str.length());
    sql.append(str);
    sql.append(") or r.id in (");
    sql.append(" select end_id  from res_relation start with start_id in ( ");
    sql.append(str);
    sql.append(") and relation_type_id  in ( select  id from relation_type  start with id = 10 connect by prior  id = parent ) connect by prior  end_id = start_id");
    sql.append("))");
}

  //System.out.println(sql.toString());
PortalService service = SpringContextHolder.getBean(PortalService.class);
List<Map<String,Object>> list = service.findListBySql(sql.toString());
%>
<div  class="blockDiv" style="background-color:#F6F7F9; border:1px solid #E2EAEC; height:18px;">
<span class="menuTitle" style="width:120px;" >产生时间</span>
<span class="menuTitle" style="width:40px;">状态</span>
<span class="menuTitle" style="width:40px;">级别</span>
<span class="menuTitle" style="margin-left:10px;">事件内容</span>
</div>

<%
int num = 0;
if(list != null && list.size() != 0){
    for(int i = 0 ; i < list.size();i++){
        String img = (list.get(i).get("STATUS").toString()).equals("0") ? "unclaimed" : "hasBeenClaimed";
        String trColor = num++%2 == 0 ? "odd" : "even";
        String msg = list.get(i).get("MSG").toString();
        if(level == -1){
            if(status == -1){
                out.println("<div class='"+trColor+"'><span style='width:120px; height:21px; float:left; display:block;'>"+list.get(i).get("OCCURTIME")+"</span><span style='width:30px; height:21px; margin-left:11px; display:block; float:left;'>"+"<img src='/bsm/style/default/bsm/images/"+img+".gif' title='"+EventConstants.getStatusDesc(Integer.valueOf(list.get(i).get("STATUS").toString()))+"'>"+"</span><span style='width:40px; height:21px; margin-left:12px; float:left; display:block;'>"+"<img src='/bsm/style/default/images/"+list.get(i).get("LV")+".gif' title='"+EventConstants.getLevelDesc(Integer.valueOf(list.get(i).get("LV").toString()))+"'>"+"</span><span style='margin-left:1%;' title='"+list.get(i).get("MSG")+"'>"+"<a href='../../event/event-view!view.action?id=" + list.get(i).get("ID") + "' target='_blank' >" +msg + "</a>"+"</span></div>");
            }else if(Integer.valueOf(list.get(i).get("STATUS").toString()).equals(status)){
                out.println("<div class='"+trColor+"'><span style='width:120px; height:21px; float:left; display:block;'>"+list.get(i).get("OCCURTIME")+"</span><span style='width:30px; height:21px; margin-left:11px; display:block; float:left;'>"+"<img src='/bsm/style/default/bsm/images/"+img+".gif' title='"+EventConstants.getStatusDesc(Integer.valueOf(list.get(i).get("STATUS").toString()))+"'>"+"</span><span style='width:40px; height:21px; margin-left:12px; float:left; display:block;'>"+"<img src='/bsm/style/default/images/"+list.get(i).get("LV")+".gif' title='"+EventConstants.getLevelDesc(Integer.valueOf(list.get(i).get("LV").toString()))+"'>"+"</span><span style='margin-left:1%;' title='"+list.get(i).get("MSG")+"'>"+"<a href='../../event/event-view!view.action?id=" + list.get(i).get("ID") + "' target='_blank'>" + msg + "</a>"+"</span></div>");
            }
        }else if(Integer.valueOf(list.get(i).get("LV").toString()).equals(level)){
            if(status == -1){
                out.println("<div class='"+trColor+"'><span style='width:120px; height:21px; float:left; display:block;'>"+list.get(i).get("OCCURTIME")+"</span><span style='width:30px; height:21px; margin-left:11px; display:block; float:left;'>"+"<img src='/bsm/style/default/bsm/images/"+img+".gif' title='"+EventConstants.getStatusDesc(Integer.valueOf(list.get(i).get("STATUS").toString()))+"'>"+"</span><span style='width:40px; height:21px; margin-left:12px; float:left; display:block;'>"+"<img src='/bsm/style/default/images/"+list.get(i).get("LV")+".gif' title='"+EventConstants.getLevelDesc(Integer.valueOf(list.get(i).get("LV").toString()))+"'>"+"</span><span style='margin-left:1%;' title='"+list.get(i).get("MSG")+"'>"+"<a href='../../event/event-view!view.action?id=" + list.get(i).get("ID") + "' target='_blank'>" + msg + "</a>"+"</span></div>");
            }else if(Integer.valueOf(list.get(i).get("STATUS").toString()).equals(status)){
                out.println("<div class='"+trColor+"'><span style='width:120px; height:21px; float:left; display:block;'>"+list.get(i).get("OCCURTIME")+"</span><span style='width:30px; height:21px; margin-left:11px; display:block; float:left;'>"+"<img src='/bsm/style/default/bsm/images/"+img+".gif' title='"+EventConstants.getStatusDesc(Integer.valueOf(list.get(i).get("STATUS").toString()))+"'>"+"</span><span style='width:40px; height:21px; margin-left:12px; float:left; display:block;'>"+"<img src='/bsm/style/default/images/"+list.get(i).get("LV")+".gif' title='"+EventConstants.getLevelDesc(Integer.valueOf(list.get(i).get("LV").toString()))+"'>"+"</span><span style='margin-left:1%;' title='"+list.get(i).get("MSG")+"'>"+"<a href='../../event/event-view!view.action?id=" + list.get(i).get("ID") + "' target='_blank'>" + msg + "</a>"+"</span></div>");
            }
        }
    }
}

%>